Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 默认值没有添加上单位, 点击事件阻止冒泡 #9204

Merged
merged 1 commit into from
Dec 22, 2023

Conversation

gooolh
Copy link
Collaborator

@gooolh gooolh commented Dec 21, 2023

What

  1. 有单位时,默认值没有添加上单位
  2. 点击事件阻止冒泡

Why

默认值未处理单位
阻止冒泡事件

How

@gooolh gooolh changed the title Fix input number fix: 默认值没有添加上单位, 点击事件阻止冒泡 Dec 21, 2023
@@ -213,6 +213,10 @@ export default class NumberControl extends React.Component<
}

this.state = {unit, unitOptions};

if (unit && value != null) {
setPrinstineValue(this.getValue(value));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补充一下初始值带单位的单测用例

@gooolh gooolh force-pushed the fix-input-number branch 2 times, most recently from 77dbabb to 3605cdd Compare December 21, 2023 06:54

const staticDom = container.querySelector('.cxd-PlainField') as Element;

expect(staticDom.innerHTML).toBe('<span class="text-muted">12px</span>');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个判断innerText就够了,不需要关心DOM结构

expect(staticDom.innerHTML).toBe('99px');

replaceReactAriaIds(container);
expect(container).toMatchSnapshot();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后面两行不需要,前面的逻辑检查足够了,不需要快照,测试单位的那个已经覆盖了

@gooolh gooolh force-pushed the fix-input-number branch 2 times, most recently from 726dd8f to 8ed8125 Compare December 21, 2023 07:31
@@ -213,6 +213,10 @@ export default class NumberControl extends React.Component<
}

this.state = {unit, unitOptions};

if (unit && value != null) {
setPrinstineValue(this.getValue(value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 value 和 this.getValue(value) 结果一样呢?是不是不应该触发?

@2betop
Copy link
Member

2betop commented Dec 21, 2023

请补充这个场景用例

form 配置 initApi,初始不带单位,通过按钮点击后,重新拉取 initApi,也没有带单位,不修改直接提交,这个数值预期应该是要带单位的。

@gooolh gooolh force-pushed the fix-input-number branch 3 times, most recently from c746d08 to 521fde3 Compare December 21, 2023 11:35
@gooolh gooolh requested a review from 2betop December 22, 2023 02:43
@hsm-lv hsm-lv merged commit 068c424 into baidu:master Dec 22, 2023
3 checks passed
unit &&
!String(value).endsWith(unit)
) {
this.props.setPrinstineValue(this.getValue(value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初步感觉有两个问题

  1. didMount 没有相关逻辑
  2. 如果 外部 value 发生变化,而且初始化之后,不应该是 setPrinstineValue 而是 onChange出去

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants